package com.ccys.cms.controller.thinkWell;

import com.ccys.cms.service.thinkWell.TblPhqDetailWebService;
import com.ccys.common.constants.ContextConstants;
import com.ccys.common.util.Kit;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.thinkWell.TblPhqDetailDTO;
import com.ccys.db.entity.TblPhqDetail;
import com.ccys.db.vo.thinkWell.TblPhqDetailWebVO;
import com.ccys.db.vo.thinkWell.TblPhqPHQ4QuestionsWebVO;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ApiIgnore
@RestController
@Api(tags = "thinkWell-phq detail(phqId 关联questions)")
@RequestMapping("thinkWell")
@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE, RequestMethod.PUT}) // 开启跨域访问允许
@SuppressWarnings("unchecked")
public class PhqDetailWebController {

    @Autowired
    private TblPhqDetailWebService tblPhqDetailWebService;

    @GetMapping("phqDetail")
    @ApiOperation("获取列表(页面中的 PHQ4 questions)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phqId", value = "phqId", required = false, dataType = "string", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 411, message = ContextConstants.DESC_411),
            @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC,response = TblPhqPHQ4QuestionsWebVO.class)
    })
    public ResponseResult listObjectsCms(HttpServletRequest request, HttpServletResponse response, @ApiIgnore TblPhqDetailDTO dto) {
        return this.tblPhqDetailWebService.listObjectsCms(request, response, dto);
    }


    @PostMapping("phqDetail")
    @ApiOperation("添加")
    @ApiResponses({
            @ApiResponse(code = 411, message = ContextConstants.DESC_411),
            @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC)
    })
    public ResponseResult save(@RequestBody TblPhqDetailDTO entity) {
        entity.setId(null);
        return this.tblPhqDetailWebService.change(entity);
    }


    @PutMapping("phqDetail")
    @ApiOperation("编辑")
    @ApiResponses({
            @ApiResponse(code = 411, message = ContextConstants.DESC_411),
            @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC)
    })
    public ResponseResult edit(@RequestBody TblPhqDetailDTO entity) {
        Kit.allParamValid(entity, "id");
        return this.tblPhqDetailWebService.change(entity);
    }


    @DeleteMapping("phqDetail")
    @ApiOperation("删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID号", required = true, dataType = "string", paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 411, message = ContextConstants.DESC_411),
            @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC)
    })
    public ResponseResult delete(TblPhqDetail dto) {
        Kit.allParamValid(dto, "id");
        return this.tblPhqDetailWebService.delete(dto);
    }

}